package com.littlebee.storysuper.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * 项目名称: CosmeticView
 * 包: hardware.pba.com.cosmeticview
 * 类描述: [类描述]
 * 创建人: linwenbing
 * 创建时间: 17/1/10下午2:23
 * 修改人: linwenbing
 * 修改备注: [说明本次修改内容]
 * 版本: [v1.0]
 */
public class AnimView extends View{
    private Paint mPaint = new Paint();
    private float mX = 0;
    private MyThread mThread;
    private RectF mRectF = new RectF(60,60,200,200);
    private float mAnlage;

    public AnimView(Context context) {
        super(context);
    }

    public AnimView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        mPaint.setColor(0xffffffff);
        canvas.drawArc(mRectF,0,360,false,mPaint);

        mPaint.setTextSize(34);
        mPaint.setColor(0xffff4666);
        mPaint.setAntiAlias(true);
        canvas.drawText("hello word",mX,100,mPaint);//通过改变X坐标的位置来实现移动
        mPaint.setStrokeWidth(5);
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawArc(mRectF,0,mAnlage,false,mPaint);
        if (mThread == null){
            mThread = new MyThread();
            mThread.start();
        }
    }

    class MyThread extends Thread{
        @Override
        public void run() {
            while (true){
                mX+=3;
                if (mX > getWidth()){
                    mX = 0 - mPaint.measureText("hello word");
                }
                if (mAnlage > 360){
                    mAnlage = 0;
                }
                mAnlage+=3;
                postInvalidate();
                try {
                    Thread.sleep(30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
